<template>
  <div>

      <div class="title">新增合同续费</div>

    <el-form ref="form" :model="form" label-width="150px">
      <el-form-item label="合同编号" class="form-1">
            <el-input v-model="form.contract_no"></el-input>
      </el-form-item>

       <el-form-item label="起始日期" required>
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.contract_startday"
            style="width: 200px"
          ></el-date-picker>
        </el-col>
      </el-form-item>

      <el-form-item label="到期日期" required>
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.contract_endday"
            style="width: 200px"
          ></el-date-picker>
        </el-col>
      </el-form-item>

      <el-form-item label="总金额" required>
        <el-input v-model="form.contract_summoney"></el-input>
        <span>元</span>
      </el-form-item>

      <el-form-item label="已收款" required>
        <el-input v-model="form.contract_receivemoney"></el-input>
        <span>元</span>
      </el-form-item>

      <el-form-item label="新到期日期" required class="newendday">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.newcontract_endday"
            style="width: 200px"
          ></el-date-picker>
        </el-col>
      </el-form-item>

      <el-form-item label="总金额(新)" required>
        <el-input v-model="form.newcontract_summoney"></el-input>
        <span>元</span>
      </el-form-item>

      <el-form-item label="已收款(新)" required>
        <el-input v-model="form.newcontract_receivemoney"></el-input>
        <span>元</span>
      </el-form-item>

      <el-form-item label="备注" class="form-1">
        <el-input
          type="textarea"
          v-model="form.newcontract_comment"
          class="remark"
        ></el-input>
      </el-form-item>

      <el-form-item label="业务员">
        <el-select v-model="form.employee_id" placeholder="请选择">
          <el-option label="超级管理员" value="0"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="success" @click="onSubmit">保存</el-button>
        <el-button type="info" @click="backList">关闭</el-button>
      </el-form-item>


    </el-form>

  </div>
</template>

<script>
import { renew } from '../../../http/apis/agreementApi'
import { timeFormat } from '../../../utils/utils'
export default {
  data(){
    return{
      form:{
        contract_no:'',
        contract_startday:'',
        contract_endday:'',
        contract_summoney:'',
        contract_receivemoney:'',
        newcontract_endday:'',
        newcontract_summoney:'',
        newcontract_receivemoney:'',
        newcontract_comment:'',
        employee_id:''
      }
    }
  },

  mounted(){
    this.form = this.$route.query
    console.log(this.form);
  },

  methods:{
    onSubmit(){

      if(!this.form.newcontract_endday){
        // console.log(this.form.newcontract_endday);
        this.$alert('到期日期不能为空', '警告', {
          confirmButtonText: '确定',
          callback: action => {
            this.$message({
              type: 'info',
              message: `action: ${ action }`
            });
          }
        });
      }else{
        if(!this.form.newcontract_summoney){
          this.form.newcontract_summoney = 0
        }
        if(!this.form.newcontract_receivemoney){
          this.form.newcontract_receivemoney = 0
        }
        this.form.newcontract_endday = timeFormat(this.form.newcontract_endday)
        this.form.newcontract_summoney = Number(this.form.newcontract_summoney)
        this.form.newcontract_receivemoney = Number(this.form.newcontract_receivemoney)
        this.form.contract_id = Number(this.form.contract_id)
        console.log(this.form);
        renew(this.form)
        .then((res)=>{
          this.$router.push({path:'/agreement/agreementNext'})
          console.log('请求成功',res);
        })
        .catch((err)=>{
          console.log('请求失败',err);
        })
      }


    },
    backList(){
      
    }
  }

}
</script>

<style>
.title{
  font-size: 18px;
  font-weight: 600;
  text-indent: 2em;
  margin-top: 10px;
}
form {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  width: 1100px;
  margin-top: 20px;
}
.el-form-item {
  width: 500px;
}
.form-1 {
  width: 1000px;
}
.el-input {
  width: 150px;
}
.btn {
  margin-left: 10px;
  box-sizing: border-box;
}
.remark {
  width: 200px;
}
.el-col-11{
  width: 80%;
}
.el-col {
   overflow: initial;
}
</style>